package cn.wolfcode.p2p.base.domain;

import com.alibaba.druid.sql.ast.statement.SQLIfStatement;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.Getter;
import lombok.Setter;
import org.springframework.format.annotation.DateTimeFormat;

import java.text.DateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

@Setter
@Getter
public class RealAuth extends BaseAuditDomain{
    public static final Integer SEX_MALE = 1; //性别男

    public static final Integer SEX_FEMALE = 0; //性别女

    private String realName; //姓名

    private Integer sex = SEX_MALE; //性别

    private String idNumber; //身份证

    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date bornDate; //出生日期

    private String address; //身份证地址

    private String image1; //身份证正面

    private String image2; //身份证反面

    public String getSexDisplay() {
        return sex == SEX_MALE ? "男" : "女";
    }

    public String getJsonString() {
        Map<String, Object> map = new HashMap();
        map.put("id", this.id);
        map.put("username", this.getApplier().getUsername());
        map.put("realname", this.realName);
        map.put("idNumber", this.idNumber);
        map.put("sex", this.getSexDisplay());
        map.put("address", this.address);
        map.put("image1", this.image1);
        map.put("image2", this.image2);
        map.put("bornDate", DateFormat.getDateInstance().format(this.bornDate));

        try {
            return (new ObjectMapper()).writeValueAsString(map);
        } catch (JsonProcessingException var3) {
            var3.printStackTrace();
            return null;
        }
    }
}
